<?php

namespace app\admin\controller\document;

use app\common\controller\Backend;

use think\Controller;
use think\Request;
use think\Db;
/**
 * 文档
 *
 * @icon fa fa-circle-o
 */
class Verify extends Backend
{

    /**
     * Document模型对象
     */
    protected $model = null;
    protected $flowtaskModel=null;
    protected $companyModel=null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('Document');
        $this->companyModel=model('Company');
        $this->view->assign('company',$this->companyModel->field('id,companyname')->select());
    }
    public function index() {
        //设置过滤方法
        $this->request->filter(['strip_tags']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('pkey_name')) {
                return $this->selectpage();
            }
            return $this->handleSearch($this->searchfields);
        }
        return $this->view->fetch();
    }
    public function verify($ids = NULL)
    {
        $template = strpos($ids, ',') !== false ? 'verify_batch' : 'verify_one';
       // echo($ids);
      // var_dump($this->model);
    // $doc= $this->model->where('id='.$ids)->select();
        $rows =  Db::name('flow_document')
    	->alias('doc')
    	->join('flow_instance instance','instance.bizobjectid=doc.id','left')    	
        ->where('doc.docid',$ids)//条件:状态为1
        ->where('instance.instancestatus',2)             
    	->field(['instance.id','doc.title'])
    	->select();
        //var_dump(json_decode($rows));
        $this->view->assign('flowlist',$rows);
        return parent::modify($ids, $template);
    }

    private function handleSearch($searchfields=null) {
        $append = array(
            array('verify','<>',1)
        );        
        list($where, $sort, $order, $offset, $limit,$orderParams) = $this->buildparams($searchfields,null,$append);
        $total = $this->model->where($where)->count();
        $list = $this->model->with('company')->where($where)->order($orderParams)->limit($offset, $limit)->select();
        $result = array("total" => $total, "rows" => $list);
        return json($result);
    }


}
